package question_answer

import (
	"news_for_deepseek_interface/controller"
	"news_for_deepseek_interface/dto"
	questionAnswerDto "news_for_deepseek_interface/dto/admin/question_answer"
	questionAnswerService "news_for_deepseek_interface/service/admin/question_answer"

	"github.com/gin-gonic/gin"
)

func Create(c *gin.Context) {

	//1. 参数绑定
	var params questionAnswerDto.CreateRequest
	if err := c.ShouldBindJSON(&params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	//2. 验证参数
	if err := dto.Validate(params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	//3. 调用服务层处理登录逻辑
	if err := questionAnswerService.Create(params); err != nil {
		controller.Fail(c, controller.BusinessError, "创建失败："+err.Error())
		return
	}

	controller.Success(c, nil)
}
